<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style></style>
  </head>
  <body>
    <div>
      <h1>ES2017</h1>
      <p>Object.values与ES2015的Object.key类似,一个返回值,一个返回键</p>
      <p>
        Object.entries是以数组的形式返回对象的所有键值,用了这个方法就可以不用自己写迭代器就可以遍历普通对象,也可以将对象转换为Map对象
      </p>
      <p>Object.getOwnPropertyDescriptors可以获取对象中的属性的完整描述</p>
      <p>
        String.prototype.padStart / String.protptype.padEnd--两个字符串填充方法
      </p>
      <p>函数在参数中添加逗号</p>
      <p>async/await</p>
    </div>
    <script>
      const obj = {
        foo: "value1",
        bar: "value2",
      };
      //   Object.values();
      console.log(Object.values(obj)); //value1 value2
      console.log(Object.keys(obj)); //foo bar

      //   Object.entries
      console.log(Object.entries(obj)); //[['foo','value1'],['bar','value2']]
      for (const [key, value] of Object.entries(obj)) {
        console.log(key, value);
        //foo value1
        //bar value2
      }
      console.log(new Map(Object.entries(obj))); //Map(2) {"foo" => "value1", "bar" => "value2"}

      //   Object.getOwnPropertyDescriptors
      const p1 = {
        firstName: "lei",
        lastName: "Wang",
        get fullName() {
          return this.firstName + " " + this.lastName;
        },
      };
      //把p1复制给p2
      const p2 = Object.assign({}, p1);
      //修改p2的值
      p2.firstName = "xjq";
      //   修改了p2之后,fullName的值没有改变,还是p1的lei wang
      console.log(p2); //{firstName: "xjq", lastName: "Wang", fullName: "lei Wang"}

      const descriptors = Object.getOwnPropertyDescriptors(p1);
      console.log(descriptors);
      const p3 = Object.defineProperties({}, descriptors);
      console.log(p3);
      p3.firstName = "xjq";
      console.log(p3.fullName); //xjq wang

      //    String.prototype.padStart / String.protptype.padEnd
      //第一个参数代表长度,第二个参数代表用上面填充
      const books = {
        css: 16,
        html: 5,
        javascript: 128,
      };

      for (const [name, value] of Object.entries(books)) {
        console.log(
          `${name.padEnd(16, "-")}|${value.toString().padStart(3, "0")}`
        );
      }
    </script>
  </body>
</html>
